package com.liuxin.common.utils;

public class UserContext {
    private static final ThreadLocal<Long> tl = new ThreadLocal<>();

    //保存当前登录用户信息到ThreadLocal
    public static void setUser(Long userId){
        tl.set(userId);
    }

    //从ThreadLocal获取当前登录用户信息
    public static Long getUser(){
        return tl.get();
    }

    //移除ThreadLocal中的当前登录用户信息
    public static void removeUser(){
        tl.remove();
    }
}
